import { NetEvent } from './NetEvent';

export class EventDispatcher {
  public engine: string;
  public eventProxy: any; //cocos cc.Node
  public dispatchEvent(event): boolean {
    if (this.eventProxy == null || this.eventProxy == undefined) this.eventProxy = NetEvent.getEventProxy();
    return this.eventProxy.dispatchEvent(event);
  }
  public addEventListener(
    type: string,
    listener: Function,
    thisObject: any,
    useCapture?: boolean,
    priority?: number,
  ): void {
    if (this.eventProxy == null || this.eventProxy == undefined) this.eventProxy = NetEvent.getEventProxy();
    switch (NetEvent.type) {
      case 'egret':
        this.eventProxy.addEventListener(type, listener, thisObject, useCapture, priority);
        break;
      case 'cocos':
        this.eventProxy.on(type, listener, thisObject, useCapture);
        break;
    }
  }
  public removeEventListener(type: string, listener: Function, thisObject: any, useCapture?: boolean): void {
    if (this.eventProxy == null || this.eventProxy == undefined) this.eventProxy = NetEvent.getEventProxy();
    switch (NetEvent.type) {
      case 'egret':
        this.eventProxy.removeEventListener(type, listener, thisObject, useCapture);
        break;
      case 'cocos':
        this.eventProxy.off(type, listener, thisObject, useCapture);
        break;
    }
  }
}
